package com.htdata.iiot.tsdb.config;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;

import com.htdata.iiot.api.tsdb.config.Configs;

/**
 * 
 * @author 孙梦亚
 *
 */
public class Cmd {
	public static void parserCmd(String[] args) {
		Options options = new Options();
		options.addOption("h", "help", false, "Print this usage information");
		options.addOption("z", "zookeeper", true, "The connection info of zk,like:master.htdata.com:2181");
		options.addOption("t", "tsdb", true, "The tsdb config node in zookeeper default is tsdb");
		options.addOption("c", "client", true, "The client config node in zookeeper default is async_client");
		options.addOption("m", "metric", false, "The data key and request metric is dn_metric ");
		CommandLine cmd=null;
		CommandLineParser parser = new BasicParser();
		try {
			cmd = parser.parse(options, args);
		} catch (org.apache.commons.cli.ParseException e1) {
			// TODO Auto-generated catch block
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("API", options);
			e1.printStackTrace();
			System.exit(0);
		}
		if(cmd.hasOption("h")){
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("API", options);
			System.exit(0);
		}
		
		if(cmd.hasOption("z")){
			System.setProperty("htiiot.zookeeper", cmd.getOptionValue("z"));
		}
		
		if(cmd.hasOption("t")){
			Configs.TSDBConfig.CONFIG_SECTION = cmd.getOptionValue("t");
		}
		
		if(cmd.hasOption("c")){
			Configs.TSDBConfig.CLIENT_CONFIG_SECTION = cmd.getOptionValue("c");
		}
		if(cmd.hasOption("m")){
			Configs.TSDBConfig.WITH_METRIC = true;
		}
		
	}

}
